﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using YDWin.Base;
using YDServices;
using YDModel;
using DevExpress.Utils;
using YDCommon;

namespace YDWin.Password
{
    public partial class EditPasswordForm : AddForm
    {
        EmployeeService es = new EmployeeService();
        public EditPasswordForm()
        {
            InitializeComponent();
 
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
           

            //判断原密码是否正确
            string oldPassword = txtOldPassword.Text;
            //判断两次输入的密码是否一致
            if (!txtUserPassword.Text.Trim().Equals(txtUserPassword2.Text.Trim()))
            {
                Utils.ShowPrompt(MessageType.mtWarning, "两次输入的密码不一致,请重新输入!\n"); 
                return;
            }

            T_Employee fact = new T_Employee();
            fact.ID = Global.User.ID;
            fact.UserPassword = Utils.Encrypt( txtUserPassword.Text);
            WaitDialogForm sdf = new WaitDialogForm("", "正在保存......");
            es.EditPassword(fact, Utils.Encrypt(oldPassword));
            sdf.Close();

            if (es.HasError)
            {
                Utils.ShowPrompt(MessageType.mtError, "修改密码失败：" + es.Errors);
                es.Errors.Clear();
                return;
            }
            Utils.ShowPrompt(MessageType.mtInformation, "密码修改成功");
            this.DialogResult = DialogResult.OK;
            this.Close();

        }

        private void EditPasswordForm_Load(object sender, EventArgs e)
        {
   
        }
 
    }
}